package com.rapida.theme;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class ThemeResources {
	private Resources mDefaultResources;
	private Resources mThemeResources;

	public ThemeResources(Resources resources) {
		mDefaultResources = resources;
	}

	public void setThemeContext(Context themeContext) {
		mThemeResources = themeContext.getResources();
	}

	public void setThemeResources(Resources resources) {
		mThemeResources = resources;
	}

	public Drawable getDrawable(int id) {
		Drawable draw;
		try {
			draw = mThemeResources.getDrawable(id);
		} catch (Exception e) {
			draw = mDefaultResources.getDrawable(id);
		}
		return draw;
	}

	public CharSequence getText(int id) {
		CharSequence text;
		try {
			text = mThemeResources.getText(id);
		} catch (Exception e) {
			text = mDefaultResources.getText(id);
		}
		return text;
	}

	public int getColor(int id) {
		int color;
		try {
			color = mThemeResources.getColor(id);
		} catch (Exception e) {
			color = mDefaultResources.getColor(id);
		}
		return color;
	}

	public String getString(int id) {
		String text;
		try {
			text = mThemeResources.getString(id);
		} catch (Exception e) {
			text = mDefaultResources.getString(id);
		}
		return text;
	}

	public float getDimension(int id) {
		float dimen;
		try {
			dimen = mThemeResources.getDimension(id);
		} catch (Exception e) {
			dimen = mDefaultResources.getDimension(id);
		}
		return dimen;
	}

	public int getDimensionPixelOffset(int id) {
		int dimen;
		try {
			dimen = mThemeResources.getDimensionPixelOffset(id);
		} catch (Exception e) {
			dimen = mDefaultResources.getDimensionPixelOffset(id);
		}
		return dimen;
	}

	public int getDimensionPixelSize(int id) {
		int dimen;
		try {
			dimen = mThemeResources.getDimensionPixelSize(id);
		} catch (Exception e) {
			dimen = mDefaultResources.getDimensionPixelSize(id);
		}
		return dimen;
	}
}
